package models

import (
	"time"
	"github.com/astaxie/beego/orm"
	"fmt"
)

type ConfigTempFree struct {
	Id          int    `orm:"column(id);auto"`
	ChannelType int8      `orm:"column(channel_type)" description:"频道类型"`
	BookId      int       `orm:"column(book_id)" description:"小说ID"`
	SortId      int       `orm:"column(sort_id)" description:"排序ID"`
	TargetDate  time.Time `orm:"column(target_date);type(date)" description:"免费日"`
	BeginTime   time.Time `orm:"column(begin_time);type(time)" description:"开始时间"`
	EndTime     time.Time `orm:"column(end_time);type(time)" description:"结束时间"`
}

func (t *ConfigTempFree) TableName() string {
	return "config_temp_free"
}

func init() {
	orm.RegisterModel(new(ConfigTempFree))
}

// AddSysCat insert a new SysCat into database and returns
// last inserted Id on success. GetAllSysCat
func GetAllConfigTempFree() ([]*ConfigTempFree,error) {
	o := orm.NewOrm()
	configTempFrees := make([]*ConfigTempFree,0)
	_, err := o.Raw("SELECT * from config_temp_free").QueryRows(&configTempFrees)
	if err != nil {
		fmt.Println("select config_temp_free error.", err)
		return nil,err
	}
	return configTempFrees, nil
}
